#include"tree.h"
#include<conio.h>

int main(){
	Tree T;
	int x, size, key;
	CreateTree(T);
	while(1){
		system("cls");
		cout<<"CHUONG TRINH DEMO CAY NHI PHAN"<<endl;
		cout<<"Vui long chon"<<endl;
		cout<<"1. Nhap du lieu"<<endl<<"2. In du lieu"<<endl;
		cout<<"3. Xoa du lieu"<<endl;
		cout<<"4. Tim du lieu"<<endl;
		cout<<"5. Xem chieu cao cua cay"<<endl;
		cout<<"6. Xem so node la'"<<endl;
		cout<<"7. Xem so node co 1 la'"<<endl;
		cout<<"8. Tinh tong cac so nguyen to trong cay"<<endl;
		cout<<"9. Tinh tong cac so chinh phuong trong cay"<<endl;
		cout<<"10. Thoat chuong trinh"<<endl;

		cin>>key;
		switch(key){
		case 1:{
			cout<<"vui long nhap so phan tu"<<endl;
			cin>>size;
			for(int i=0; i<size; i++){
				cout<<"nhap du lieu"<<endl;
				cin>>x;
				AddTNode(T,x);
			}
			cout<<"ban co muon nhap them"<<endl;
			char key1=getch();
			while(key1=='y' || key1=='Y'){
				cout<<"nhap du lieu"<<endl;
				cin>>x;
				AddTNode(T,x);
				cout<<"ban co muon nhap them"<<endl;
				key1=getch();
			}
			//PrintTree(T.Root);

			system("pause");
			break;
			   }

		case 2:{
			PrintTree(T);
			system("pause");
			break;
			   }
		case 3:{
		
				int key;
				cout<<"vui long nhap gia tri can xoa"<<endl;
				cin>>key;
				DeleteTNode (T, key);
								
			system("pause");
			break;
			   }
		case 4:{
			int search;
			cout<<"vui long nhap phan tu can tim"<<endl;
			cin>>search;
			if(SearchKey(T, search))
			{cout<<"co trong cay"<<endl;
			}
			else 
			{cout<<"khong co trong cay"<<endl;
			}
			system("pause");
			break;
			   }
		case 5:{
			if(T == NULL){
				break;
			}
			
			TreeHeight(CountTNode (T));
			system("pause");
			break;
			   }
		case 6:{
			cout<<"so la cua cay la: "<<CountLeaf(T)<<endl;
			system("pause");
			break;
			   }
		case 7:{
			cout<<"so node co 1 la: "<<CountLeaf1(T)<<endl;
			system("pause");
				break;
			   }
		case 8:{
			cout<<"tong cac so nguyen to la: "<<SumPrimeNum(T)<<endl;
			system("pause");
			break;
			   }
		case 9:{
			cout<<"tong cac so chinh phuong la: "<<SumSquareNum(T)<<endl;
			system("pause");
			break;
			   }
		case 10:{
			/*DeleteTree(T);*/
			exit(0);
			   }
		default:
			system("pause");
			continue;

		}
	}
}
